import cv2


import os
import sys
# path = r"E:\2019PythonProject\20200903SprayData\Tarpa4Class\uncover"
# path = r"E:\2019PythonProject\20200903SprayData\Tarpa4Class\empty"
path = r"E:\2019PythonProject\20200903SprayData\Tarpa4Class\cover"
fileList = os.listdir(path) 
img_num = 0
all_num = {}
for fileName in fileList:
    # try:
    new_name_1 =str(fileName.split('-')[0].strip())
    # new_name_1 =str(fileName.split('_')[0].strip())
    if new_name_1 not in all_num.keys():
        all_num[new_name_1] = 0
    all_num[new_name_1] += 1
    new_name = new_name_1 + '_'+ str(all_num[new_name_1]) + '.jpg'
    # new_name = new_name_1 + '-'+ str(all_num[new_name_1]) + '.jpg'
    # print(new_name)
    os.rename(path +'/'+ fileName,path+'/'+ new_name)  # 文件重新命名
    print(path+'\\'+ new_name)
    
    origin_img= cv2.imread(path+'/'+ new_name)
    img_num += 1 
    if origin_img.shape[0] == 512 and origin_img.shape[1]==512:
        continue
    else:
        print(origin_img.shape)
        origin_img = cv2.resize(origin_img,(512,512))
        print(origin_img.shape)
        cv2.imwrite(path +'/'+new_name,origin_img)
    # break
    # except:

    #     print('error=====================================')
    #     print(fileName)
    #     break
     
# origin_img = cv2.imread(r'E:\2019PythonProject\20200903SprayData\Tarpa4Class\uncover\10_1.jpg')
# print(origin_img)
print(all_num)  
print(img_num)
